<template>
  <div>
    <el-container>
<!--      头部-->
      <el-header class="layout-header">
        <div class="login-user">
          <span class="welcome">欢迎回来，root</span>
          <el-dropdown>
            <el-avatar size="small" src="https://cube.elemecdn.com/3/7c/3ea6beec64369c2642b92c6726f1epng.png"></el-avatar>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item icon="el-icon-edit">修改资料</el-dropdown-item>
              <el-dropdown-item icon="el-icon-picture-outline-round">修改头像</el-dropdown-item>
              <el-dropdown-item icon="el-icon-s-open">修改密码</el-dropdown-item>
              <el-dropdown-item icon="el-icon-switch-button" divided>退出登录</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </div>
        <div >
          <h1>小明二手车管理平台</h1>
        </div>
      </el-header>

      <el-container class="layout-body">
<!--        左侧边菜单栏-->
        <el-aside width="200px" class="layout-aside">
<!-- 从所有路由里面找到当前路径的网址:default-active="$router.currentRoute.path"-->
          <el-menu
              router="true"
              :default-active="activeMenuItemPath"
              class="el-menu-vertical-demo"
              background-color="#545c64"
              text-color="#fff"
              active-text-color="#fff">
<!--            首页-->
            <el-menu-item index="/admin">
              <i class="el-icon-menu"></i>
              <span slot="title">首页</span>
            </el-menu-item>
<!--                车辆管理-->
            <el-submenu index="2">
              <template slot="title">
                <i class="el-icon-truck"></i>
                <span>车辆管理</span>
              </template>
              <el-menu-item index="/admin/brand/brandList">
                <i class="el-icon-s-flag"></i>
                <span slot="title">品牌管理</span>
              </el-menu-item>
              <el-menu-item index="/admin/series/seriesList">
                <i class="el-icon-s-unfold"></i>
                <span slot="title">车系管理</span>
              </el-menu-item>
              <el-menu-item index="/sys-admin/product/album">
                <i class="el-icon-guide"></i>
                <span slot="title">款式管理</span>
              </el-menu-item>
              <el-menu-item index="/sys-admin/product/category">
                <i class="el-icon-c-scale-to-original"></i>
                <span slot="title">分类管理</span>
              </el-menu-item>
              <el-menu-item index="/sys-admin/product/attributeTemplate">
                <i class="el-icon-cpu"></i>
                <span slot="title">参数管理</span>
              </el-menu-item>
              <el-menu-item index="2-6">
                <i class="el-icon-menu"></i>
                <span slot="title">属性管理</span>
              </el-menu-item>
              <el-menu-item index="/admin/brand/CarList">
                <i class="el-icon-menu"></i>
                <span slot="title">车辆信息管理</span>
              </el-menu-item>
            </el-submenu>
<!--           订单管理 -->
            <el-submenu index="3">
              <template slot="title">
                <i class="el-icon-s-management"></i>
                <span>订单管理</span>
              </template>
              <el-menu-item index="/admin/order/orderList">
                <i class="el-icon-tickets"></i>
                <span slot="title">订单管理</span>
              </el-menu-item>
            </el-submenu>
            <el-submenu index="4">
              <template slot="title">
                <i class="el-icon-sell"></i>
                <span>营销管理</span>
              </template>
              <el-menu-item index="4-1" disabled>
                <i class="el-icon-menu"></i>
                <span slot="title">暂无内容</span>
              </el-menu-item>
            </el-submenu>
            <el-submenu index="5">
              <template slot="title">
                <i class="el-icon-s-shop"></i>
                <span>商家管理</span>
              </template>
              <el-menu-item index="5-1" disabled>
                <i class="el-icon-menu"></i>
                <span slot="title">暂无内容</span>
              </el-menu-item>
            </el-submenu>
            <el-submenu index="6">
              <template slot="title">
                <i class="el-icon-s-check"></i>
                <span>权限管理</span>
              </template>
              <el-menu-item index="/sys-admin/permission/admin">
                <i class="el-icon-s-custom"></i>
                <span slot="title">管理员管理</span>
              </el-menu-item>
            </el-submenu>
          </el-menu>
        </el-aside>

<!--          右边显示区域-->
        <el-main class="layout-main">
          <router-view/>
        </el-main>

      </el-container>
    </el-container>
  </div>
</template>

<script>
export default {
  data() {
    return {
      activeMenuItemPath:''
    };
  },
  methods: {
    handleActiveMenuItem(){
      let currentPath=this.$router.currentRoute.path;
      if (currentPath.startsWith('/admin/brand')){
        this.activeMenuItemPath='/admin/brand/brandList';
      }else if (currentPath.startsWith('/admin/order')){
        this.activeMenuItemPath='/admin/order/orderList';
      }else if (currentPath.startsWith('/admin/series')){
        this.activeMenuItemPath='/admin/series/seriesList';
      }else if (currentPath.startsWith('/sys-admin/product/brand')){
        this.activeMenuItemPath='/sys-admin/product/brand';
      }else if (currentPath.startsWith('/sys-admin/product/category')){
        this.activeMenuItemPath='/sys-admin/product/category';
      }else if (currentPath.startsWith('/sys-admin/product/spu')){
        this.activeMenuItemPath='/sys-admin/product/spu/add-new-1';
      }
    },

  },
  craeted(){

  },
  mounted(){//这个跟created一样也是打开页面就会
    //先有created再有mounted，习惯用这个多
    this.handleActiveMenuItem();//处理菜单
  }
}
</script>

<style>
  .layout-aside i{
    color: #fff !important;
  }
  .layout-aside .el-menu{
    border: 0;
  }
  .layout-aside{
    background: #545c64;
  }
  .layout-header{
    background:#2c3e50;
  }
  .layout-header h1{
    line-height: 60px;
    color: #fff;
  }
  .layout-body{
    position: absolute;
    top: 60px;
    bottom: 0;
    left: 0;
    right: 0;
  }

  .login-user{
    float: right;
    display: flex;
    margin-top: 16px;
    margin-right: 10px;
    color: white;
  }
  .welcome{
    line-height: 28px;
    margin-right: 10px;
  }
  .layout{
    border: 10px solid red;
  }
  .el-menu-item.is-active{/*添加选中样式*/
    background: #2c3e50 !important;
  }
  .layout-main{
    background-color: white;
  }
  *{
    margin: 0;
    padding: 0;
    font-family: Avenir, Helvetica, Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
  }

  #app {
    color: #2c3e50;
  }
</style>